<%@ page import="com.MusicWeb.service.UserService" %>
<%@ page import="com.MusicWeb.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: ybyb
  Date: 2021/4/10
  Time: 14:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    Cookie[] cookies = request.getCookies();
    String tokenValue = "";
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals("token")) {
                tokenValue = cookies[i].getValue();
            }
        }
    }
    UserService userService = new UserService();
    User user = null;
    user = userService.Selecttoken(tokenValue);
    //如果token 与 user 一起为空 就返回登录页
    if (!tokenValue.equals("") && user != null) {
        session.setAttribute("user", user);
        session.setAttribute("msg", "欢迎" + user.getAccount());
        return;
    } else {
        session.setAttribute("msg", "请登录");
        response.sendRedirect(request.getContextPath() + "/login.jsp");
    }

%>
